package fristphase.day9_23.submarine;

import javax.swing.*;
import java.awt.*;
import java.util.Random;

public abstract class SeaObject {
    private int width,height,x,y,speed;//640,480
    private final static int DEAD = 0;
    private final static int LIVE = 1;
    private int state = LIVE;

    public SeaObject(int width,int height){
        this.width = width;
        this.height = height;
        Random random = new Random();
        y = random.nextInt(480 - 150 - height+1 )+150;
        x = -width;
        speed = random.nextInt(3)+1;
    }

    public SeaObject(int width, int height, int x, int y,int speed) {
        this.width = width;
        this.height = height;
        this.x = x;
        this.y = y;
        this.speed = speed;
    }

    public abstract void move();
    public abstract ImageIcon getImage();

    public void paintImage(Graphics g){
        if(state == LIVE) getImage().paintIcon(null,g,x,y);
    }
    public void isDead(){
        state = DEAD;
    }


    public boolean getLive(){
        return state == LIVE;
    }

    public boolean getDead(){
        return state == DEAD;
    }

    public boolean isBound(){
        return x >= World.WIDTH;
    }

    public boolean isHit(SeaObject other){
        int x1 = other.x - width;
        int x2 = other.x + other.width;
        int y1 = other.y - height;
        int y2 = other.y + other.height;
        return x1 <= x && x2 >= x && y1 <= y && y2 >= y;
    }

    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getSpeed() {
        return speed;
    }

    public void setSpeed(int speed) {
        this.speed = speed;
    }
}
